load("//bazel:api.bzl", "modular_generate_stubfiles", "modular_nanobind_extension", "modular_py_library", "requirement")

modular_nanobind_extension(
    name = "_core.bindings",
    srcs = ["//max/python/max/_core/internal:_core.cpp"],
    module_name = "_core",
    new_link_root = "../modular/lib",
    deps = [
        "//Support:NanobindUtils",
        "//max/python/max/_core/internal/modules",
        "@llvm-project//llvm:Support",
    ],
)

modular_generate_stubfiles(
    name = "_core",
    additional_update_targets = ["//max/python/max/_mlir/_mlir_libs:_mlir.sync-stubfiles"],
    diff_test_failure_message = """
A stubfile is out of sync with its generated counterpart.
If you modified just a .pyi file, you need to modify the corresponding .cpp file instead.
When you modify a .cpp file in the _core/src directory, you can run
'./utils/sync-stubfiles.sh' and commit the results.
""",
    extension = ":_core.bindings",
    full_name = "max._core",
    header = """
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2025, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
# GENERATED FILE, DO NOT EDIT MANUALLY!
# ===----------------------------------------------------------------------=== #
""",
    imports = [".."],
    include_private = True,
    pattern_file = "//max/python/max/_core/internal:patterns.nb",
    pyi_srcs = glob(["**/*.pyi"]),
    deps = [
        "//max/python/max/_core_types",
        "//max/python/max/mlir",
        requirement("numpy"),
    ],
)

modular_py_library(
    name = "max",
    srcs = [],
    imports = [".."],
    deps = [
        ":_core",
        "//max/python/max/_core_mojo",
        "//max/python/max/driver",
        "//max/python/max/dtype",
        "//max/python/max/engine",
        "//max/python/max/entrypoints",
        "//max/python/max/entrypoints:gpu-query",
        "//max/python/max/entrypoints:pipelines",
        "//max/python/max/entrypoints:replay_recording",
        "//max/python/max/experimental",
        "//max/python/max/graph",
        "//max/python/max/interfaces",
        "//max/python/max/mlir",
        "//max/python/max/nn",
        "//max/python/max/pipelines",
        "//max/python/max/pipelines/architectures",
        "//max/python/max/profiler",
        "//max/python/max/serve",
        "//max/python/max/support",
        "//max/python/max/torch",
    ],
)
